<?php

namespace App\Http\Controllers\Admin;

use App\Models\RefundReason;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class RefundReasonController extends BaseController
{
    public function index()
    {
        if ($this->isOnSubmit())
        {
            $delete = $this->request->input('delete');
            if ($delete) {
                RefundReason::whereIn('id', $delete)->delete();
            }

            $items = $this->request->input('items');
            if ($items)
            {
                foreach ($items as $id=>$item)
                {
                    if ($id > 0)
                    {
                        RefundReason::where('id', $id)->update($item);
                    } else {
                        RefundReason::insert($item);
                    }
                }
            }

            return $this->messager()->render();
        } else {

            $items = RefundReason::orderBy('displayorder')->get();
            return $this->view('admin.common.refundreason', compact('items'));
        }
    }
}
